package ac.svn.accesscontrol.ui;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.LayoutManager;
import java.awt.Paint;
import java.awt.RadialGradientPaint;
import java.awt.RenderingHints;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;
import java.awt.geom.Point2D;
import java.awt.geom.RoundRectangle2D;

import javax.swing.JFrame;
import javax.swing.JPanel;

public class GlassPanel extends JPanel {

    /**
     * 
     */
    private static final long serialVersionUID = 1L;
    private JPanel component;

    public GlassPanel() {
	super(true);
	addRepainter();
    }


    public GlassPanel(LayoutManager arg0) {
	super(arg0);
	addRepainter();
    }

    public GlassPanel(boolean arg0) {
	super(arg0);
	addRepainter();
    }

    public GlassPanel(LayoutManager arg0, boolean arg1) {
	super(arg0, arg1);
	addRepainter();
    }


    private void addRepainter() 
    {

	setFocusable(false);
	setFocusCycleRoot(false);

	addComponentListener(new ComponentListener() {
	    @Override
	    public void componentShown(ComponentEvent arg0) {
	    }
	    @Override
	    public void componentResized(ComponentEvent arg0) {
		repaint();
	    }
	    @Override
	    public void componentMoved(ComponentEvent arg0) {
	    }
	    @Override
	    public void componentHidden(ComponentEvent arg0) {
	    }
	});

    }

    @Override
    protected void paintComponent(Graphics g) {
	Graphics2D g2 = (Graphics2D) g;
	g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

	/*g2.setColor(Color.GREEN);
	Paint radical = new GradientPaint(0,0,Color.GRAY,0,getHeight()/2,Color.WHITE);
	g2.setPaint(radical);
	g2.fill(new RoundRectangle2D.Double(0,0,getWidth(),getHeight(),5,5));
	paintComponents(g);*/

	g2.setColor(Color.GREEN);
	Paint radical = new RadialGradientPaint(new Point2D.Double(getWidth()/2,getHeight()), getWidth(),
		new float[] { 0.0f, 0.7f, 1.0f },
		new Color[] {Color.WHITE,Color.GRAY,Color.DARK_GRAY});
	g2.setPaint(radical);

	g2.fill(new RoundRectangle2D.Double(0,0,getWidth(),getHeight(),5,5));
    }





    /* (non-Javadoc)
     * @see javax.swing.JComponent#setVisible(boolean)
     */
    @Override
    public void setVisible(boolean b) {
	if(b)
	{
	    repaint();
	}
	super.setVisible(b);
    }


    /**
     * @param parent the parent to set
     */
    public void setParent(JFrame parent) {
	if(null != parent)
	{
	    parent.addComponentListener(new ComponentListener() {

		@Override
		public void componentShown(ComponentEvent arg0) {

		}

		@Override
		public void componentResized(ComponentEvent arg0) {

		}

		@Override
		public void componentMoved(ComponentEvent arg0) {

		}

		@Override
		public void componentHidden(ComponentEvent arg0) {

		}
	    });
	}

    }


    /**
     * @return the component
     */
    public JPanel getComponent() {
	return component;
    }


    /**
     * @param component the component to set
     */
    public void setComponent(JPanel component) {
	this.component = component;
	if(null != component)
	{
	    component.addComponentListener(new ComponentListener() {

		@Override
		public void componentShown(ComponentEvent arg0) {

		}

		@Override
		public void componentResized(ComponentEvent arg0) {

		}

		@Override
		public void componentMoved(ComponentEvent arg0) {

		}

		@Override
		public void componentHidden(ComponentEvent arg0) {

		}
	    });
	}
    }

    
    public void positionComponent(Dimension dimension)
    {
	
    }


}
